import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params} from '@angular/router';
import { CusindexService } from './service/cusindex.service';
import { RootObject, Card, Cardkind, ConsumeList, Custom } from './service/rootObject';

@Component({
  selector: 'app-cusindex',
  templateUrl: './cusindex.component.html',
  styleUrls: ['./cusindex.component.css']
})
export class CusindexComponent implements OnInit {

  public customno: number;
  public isCard: Boolean;
  public isConsume: Boolean;
  public weChatName: string;
  public weChatHeah: string;




  constructor(
    private routerIonfo: ActivatedRoute,
    public cusindexService: CusindexService
  ) {
    this.isCard = true;
    this.isConsume = false;
   }

  cardClick() {
    this.isCard = !this.isCard ;
  }

  consumeList() {
    this.isConsume = !this.isConsume;
  }

  // tslint:disable-next-line:member-ordering
  consumes: RootObject;
  // tslint:disable-next-line:member-ordering
  cards: Card[];
  // tslint:disable-next-line:member-ordering
  cardkind: Cardkind[];
  // tslint:disable-next-line:member-ordering
  consumelist: ConsumeList[];
  // tslint:disable-next-line:member-ordering
  cardlength: number;
  // tslint:disable-next-line:member-ordering
  customStatu: number;
  // tslint:disable-next-line:member-ordering
  customlength: Boolean;
  // tslint:disable-next-line:member-ordering
  fcustomlength: Boolean;

  getconsumet(id: number) {
    this.cusindexService.getconsume(id).subscribe((res: RootObject) => {
      console.log(res);

      if (res.custom !== undefined) {
        this.consumes = res;
        console.log(this.consumes);
        this.cards = res.cards;

        this.cardlength = res.cards.length;
        this.consumelist = res.consumeList;
        this.fcustomlength = true;
        this.customStatu = res.consumeList.length;

        this.weChatName = res.custom.wechatnickname + '(' + res.custom.customname + ')';
        this.weChatHeah = res.custom.wechathead;
        if (this.weChatName === undefined) {
          this.weChatName = '暂未绑定微信';
          this.weChatHeah = 'assets/img/head.png';
        }
      }else if (res.custom === undefined) {
        this.customlength = true;
      }
    });
  }

  ngOnInit() {
    console.log('init');
    this.customno = this.routerIonfo.snapshot.queryParams['state'];
    console.log(this.customno);
    this.getconsumet(this.customno);
  }

}
